package com.situ.science.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.situ.science.mapper.ProcessMapper;
import com.situ.science.pojo.Process;
import com.situ.science.pojo.query.ProcessQuery;
import com.situ.science.pojo.vo.ProcessVO;
import com.situ.science.service.IProcessService;
import com.situ.science.utils.PageRusults;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ProcessServiceImpl implements IProcessService {

    @Autowired
    private ProcessMapper processMapper;


    @Override
    public PageRusults selectByPage(ProcessQuery processQuery) {
        int limit = processQuery.getLimit()!= null? processQuery.getLimit() : 10; // 设置默认值为 10，如果 limit 为 null
        int page = processQuery.getPage()!= null? processQuery.getPage() : 1;

        PageHelper.startPage(page, limit);
        //1.查询当前页列表
        List<ProcessVO> processList = processMapper.selectByPage(processQuery);
        //2.用一个小插件查询总数量
        PageInfo pageInfo = new PageInfo(processList);
        int total = (int) pageInfo.getTotal();
        return new PageRusults(0,"",total,processList);
    }

    @Override
    public void add(Process process) {
        processMapper.add(process);
    }
}
